package org.szrcb.temu.SalesManage.dao;

import org.apache.ibatis.annotations.*;
import org.szrcb.temu.SalesManage.pojo.UserInfo;

@Mapper
public interface UserInfoDao {
    @Select("SELECT count(1) FROM user_info WHERE user_id = #{userId}")
    int countUserInfo(@Param("userId") String userId);

    @Insert("INSERT into user_info values (#{user.userId}, #{user.maskMobile},#{user.maskOwnerMobile},#{user.accountType},#{user.accountStatus},#{user.tokenType})")
    void insertUserInfo(@Param("user") UserInfo user);

    @Update("UPDATE user_info SET mask_mobile = #{user.maskMobile},mask_owner_mobile = #{user.maskOwnerMobile},account_type = #{user.accountType},account_status = #{user.accountStatus},token_type = #{user.tokenType} WHERE user_id = #{user.userId}")
    void updateUserInfo(@Param("user") UserInfo user);

    @Select("SELECT user_id FROM user_token WHERE access_token = #{accessToken}")
    String queryUserId(@Param("accessToken") String accessToken);

    @Select("SELECT cookie FROM user_token WHERE access_token = #{accessToken}")
    String queryUserCookie(@Param("accessToken") String accessToken);

    @Select("SELECT count(1) FROM user_token WHERE user_id = #{userId}")
    int countUserTokenInfo(@Param("userId") String userId);

    @Insert("INSERT INTO user_token values (#{userId},#{cookie},#{token})")
    void insertUserToken(@Param("userId") String userId, @Param("cookie")String cookie, @Param("token")String token);

    @Update("UPDATE user_token SET cookie = #{cookie},access_token = #{token} WHERE user_id = #{userId}")
    void updateUserToken(@Param("userId") String userId, @Param("cookie")String cookie, @Param("token")String token);

    @Select("SELECT access_token FROM user_token WHERE user_id = #{userId} AND cookie = #{cookie}")
    String queryAccessToken(@Param("userId") String userId,@Param("cookie") String cookie);
}
